package com.example.spring.util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.PreparedStatement;

public class MajeDataMysql {

    public static void main(String[] args) throws Exception{

        BufferedReader br = new BufferedReader(new FileReader("F:\\数加\\代码\\bigdatespring\\data\\students.txt"));
        String line;
        while ((line=br.readLine())!=null){

            String[] split=line.split(",");
            String id = split[0];
            String name = split[1];
            String sex = split[3];
            int age = Integer.parseInt(split[2]);
            String clazz = split[4];

            //将数据存入数据库
            Connection conn = JDBCUtil.getConn();
            PreparedStatement statement = conn.prepareStatement("insert into student(id,name,age,sex,clazz) values(?,?,?,?,?)");


            for (int i = 0; i < 1000; i++) {

                String newId=id+i;
                statement.setString(1,newId);
                statement.setString(2,name);
                statement.setInt(3,age);
                statement.setString(4,sex);
                statement.setString(5,clazz);
                statement.addBatch();

            }

            statement.executeBatch();
            System.out.println("1000条插入成功");
        }

    }
}
